<template>
<el-container>
  <el-main>
    <el-form ref="project" :model="project" label-width="80px">
      <el-row>
        <el-col :span="8">
          <el-form-item label="项目编号">
            <el-select v-model="project.xm" placeholder="请选择项目编号" style="width: 100%;" @change="selectProject">

              <el-option v-for="v in projectList" :value="v" :key="v.id" :label="v.batch_id"></el-option>

            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="招标公司">
            <el-input v-model="project.company" disabled placeholder="请选择项目编号"></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="项目名称">
            <el-input v-model="project.name" disabled placeholder="请选择项目编号"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="8">
          <el-form-item label="开始时间">
            <el-date-picker type="datetime" placeholder="选择日期" v-model="project.start_at" style="width: 100%;" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="截止时间">
            <el-date-picker type="datetime" placeholder="选择日期" v-model="project.end_at" style="width: 100%;" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="报价次数">
            <el-input v-model="project.rows" type="number"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="8">
          <el-form-item label="限价金额">
            <el-input v-model="project.limit_money"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="降价幅度">
            <el-input v-model="project.reduce_money"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-form-item>
        <uploadFile :params="fileParams" @test="getFiles"></uploadFile>
      </el-form-item>

      <el-form-item style="text-align: center;">
        <el-button type="primary" @click="commitOrder">立即提交</el-button>
      </el-form-item>
    </el-form>
  </el-main>
</el-container>
</template>

<script>
    import uploadFile from "@/components/common/uploadFile";

    import {addOrder,getOrderByXmid} from '@/apilist/Supplier'
    export default {
        name: "systemInfo",
        data(){
            return {
                project: {
                    batch_id: '',
                    name: '',
                    company: '',
                    files: [],
                    start_at: '',
                    end_at: '',
                    rows: 0,
                    limit_money: 0,
                    reduce_money: 0,
                    xm: {},
                    xmid: '',
                },
                fileParams: {
                    dir: 'purchase',
                    fileList: [],
                },
            }
        },
        components: {
            uploadFile,
        },

        props: ['projectList'],
        methods: {
            selectProject(){
                let xm = this.project.xm
                this.project.batch_id = xm.batch_id
                this.project.company = xm.company
                this.project.name = xm.name
                this.project.xmid = xm.id
                getOrderByXmid({xmid: xm.id}).then(res => {
                    if(res.data){
                        this.project.start_at = res.data.start_at
                        this.project.end_at = res.data.end_at
                        this.project.rows = res.data.rows
                        this.project.limit_money = res.data.limit_money
                        this.project.reduce_money = res.data.reduce_money
                        this.fileParams.fileList = JSON.parse(res.data.files)
                        this.getFiles(JSON.parse(res.data.files));
                    }
                });


            },
            commitOrder()
            {
                console.log(this.project)
                //return
                addOrder(this.project).then(res => {
                    if(res.state == 'ok'){
                        this.$message({
                            type: 'success',
                            message: res.msg,
                            onClose: ()=>{
                                this.resetForm()
                            }
                        })
                    }
                })
            }
            ,getFiles(files)
            {
                this.project.files = files
            },
            resetForm() {
                for (let k of Object.keys(this.project)) {
                    this.obj.k = '';
                }
            }
        }
    }
</script>

<style scoped>

</style>
